import { axios } from '@/utils/ask'
import qs from 'qs'

// 登录接口
export const loginWithPassword = (data) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/oauth/login',
      data: data,
      method: 'post',
      headers: {
        'Authorization': 'Basic Y2Nsb3VkX2Jsb2c6MTIz',
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 注册接口
export const registerUser = (data) => {
  return new Promise((resolve, reject) => {
    axios.request({
      contentType: 'application/x-www-form-urlencoded',
      url: '/oauth/register',
      data,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取用户基础信息
export const getUserInfo = (data) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/system/user/getUserInfo',
      data,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 更新用户信息
export const updateUserInfo = (data) => {
  return new Promise((resolve, reject) => {
    axios.request({
      contentType: 'application/x-www-form-urlencoded',
      url: '/system/user/update',
      data,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
